{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 <class 'int'>\n",
      "12.34 <class 'float'>\n",
      "Hello <class 'str'>\n",
      "True <class 'bool'>\n",
      "False <class 'bool'>\n",
      "[1, 2, 3] <class 'list'>\n",
      "(1, 2, 3) <class 'tuple'>\n",
      "{1, 2, 3} <class 'set'>\n",
      "{'name': 'Jerry', 'age': 12} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "a = 10\n",
    "print(a, type(a))\n",
    "a = 12.34\n",
    "print(a, type(a))\n",
    "a = \"Hello\"\n",
    "print(a, type(a))\n",
    "a = True\n",
    "print(a, type(a))\n",
    "a = False\n",
    "print(a, type(a))\n",
    "a = [1, 2, 3]\n",
    "print(a, type(a))\n",
    "a = (1, 2, 3)\n",
    "print(a, type(a))\n",
    "a = {1, 2, 3}\n",
    "print(a, type(a))\n",
    "a = {\"name\": \"Jerry\", \"age\": 12}\n",
    "print(a, type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "-1\n",
      "6\n",
      "3.5\n",
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "print(1 + 2)\n",
    "print(1 - 2)\n",
    "print(2 * 3)\n",
    "print(7 / 2)    # 普通除法\n",
    "print(9 % 4)    # 模数运算，取余数\n",
    "print(9 // 4)   # 整除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.7320508075688772\n",
      "2.718281828459045\n",
      "8.0\n"
     ]
    }
   ],
   "source": [
    "import math             # 数学库\n",
    "\n",
    "print(math.sqrt(3))     # 平方根\n",
    "print(math.e)           # 自然对数的底\n",
    "print(math.pow(2, 3))   # 指数函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "可以参军\n"
     ]
    }
   ],
   "source": [
    "age = 19\n",
    "gender = 'male'\n",
    "\n",
    "if age > 18 and gender == 'male':\n",
    "    print('可以参军')\n",
    "else:\n",
    "    print('不可以参军')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "red\n",
      "green\n",
      "blue\n",
      "A\n",
      "l\n",
      "i\n",
      "c\n",
      "e\n",
      "Alice 80\n",
      "Bob 90\n",
      "Charlie 85\n"
     ]
    }
   ],
   "source": [
    "# 使用for循环迭代元组\n",
    "colors = ('red', 'green', 'blue')\n",
    "for color in colors:\n",
    "    print(color)\n",
    "\n",
    "# 使用for循环迭代字符串\n",
    "name = 'Alice'\n",
    "for char in name:\n",
    "    print(char)\n",
    "\n",
    "# 使用for循环迭代字典\n",
    "scores = {'Alice': 80, 'Bob': 90, 'Charlie': 85}\n",
    "for name, score in scores.items():\n",
    "    print(name, score)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
